<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Notification</title>
    </h:head>
    <h:body>
        Logged user: #{userBean.name}<br/>
        <p:link outcome="home" value="home"/><br />
        <h:form>
            <p:commandLink action="#{loginBean.logout()}" value="logout"/>
        </h:form>
        <br /><br />
        <h:form >
            <p:panel header="Invite Notification">
                <br /><br />
                <h:panelGrid>                    
                    <ui:repeat var="i" value="#{notificationView.inviteList}" > 
                        <h:panelGroup rendered="#{i.status.name()=='PENDING'}" style="font-weight: bold;">
                            <h:outputText value="#{i.event.creator.name} " />
                            <h:outputText value="#{i.event.creator.surname}" />
                            <h:outputText value=" has invited you at event: " />
                            <h:outputText value="#{i.event.title}" />
                            <h:outputText value=", from " />
                            <h:outputText value="#{i.event.startTime.getTime()}" >
                                <f:convertDateTime pattern="dd/MM/yyyy hh:mm" timeZone="GMT+1"/>
                            </h:outputText>

                            <h:outputText value=" to " />
                            <h:outputText value="#{i.event.endTime.getTime()}" >
                                <f:convertDateTime pattern="dd/MM/yyyy hh:mm" timeZone="GMT+1"/>
                            </h:outputText>
                            <h:outputText value=", in " />
                            <h:outputText value="#{i.event.location}" />
                            <h:outputText value=" " />
                            <p:commandButton id="accept" value="Accept" action="#{notificationView.accept(i)}" ajax="true" update="@all"/> 
                            <p:commandButton id="decline" value="Decline" action="#{notificationView.decline(i)}" ajax="true" update="@all"/>
                            <br /><br />
                        </h:panelGroup>
                    </ui:repeat>    
                </h:panelGrid>
                <h:panelGrid>
                    <ui:repeat var="i" value="#{notificationView.inviteList}" >
                        <h:panelGroup rendered="#{!(i.status.name()=='PENDING')}" >
                            <h:outputText value="You accepted event: " rendered="#{i.status.name()=='ACCEPTED'}"/>
                            <h:outputText value="You declined event: " rendered="#{i.status.name()=='DECLINED'}"/>
                            <h:outputText value="#{i.event.title}" />
                            <br /><br />                        
                        </h:panelGroup>
                    </ui:repeat>
                </h:panelGrid>
            </p:panel>
            <br /><br />
            <p:panel header="Weather Notification">
                <br /><br />
                <h:panelGrid columns="1" >                    
                    <ui:repeat var="s" value="#{notificationView.systemNotificationList}" >
                        <h:panelGroup rendered="#{s.unread}" style="font-weight: bold;" >
                            <h:outputText value="#{s.event.title} has bad weather next sunny day: " /> 
                            <h:outputText value="#{s.nextSunny.time}" >
                            <f:convertDateTime pattern="dd/MM/yyyy hh:mm" timeZone="GMT+1"/>
                            </h:outputText>
                            <p:commandButton id="accept5" rendered="#{s.nextSunny!=null}" value="Automatic Reschedule" action="#{eventBean.reschedule(s.event,s.nextSunny,s.weatherCode)}" ajax="true" update="@all"/>
                            <p:commandButton id="accept7" rendered="#{s.unread}" value="ok" action="#{eventBean.leggi(s.event)}" ajax="true" update="@all"/>
                            <p:commandButton id="accept6" rendered="#{s.unread and s.nextSunny==null and s.event.creator.email==userBean.email}" value="Reschedule" action="#{eventBean.leggi(s.event)}" ajax="true" update="@all"/>
                            <br /><br />                        
                        </h:panelGroup>
                    </ui:repeat>
                </h:panelGrid>
            </p:panel>
            <br /><br />
            <p:panel header="Friendship Notification">
                <br /><br />
                <h:panelGrid>                    
                    <ui:repeat var="j" value="#{notificationView.friendNotificationList}" > 
                        <h:panelGroup rendered="#{j.unread}" style="font-weight: bold;">
                            <h:outputText value="#{j.sender.name} " />
                            <h:outputText value="#{j.sender.surname}" />
                            <h:outputText value=" request your friendship" />
                            <p:commandButton id="accept2" value="Accept" action="#{notificationBean.accetta(j.sender)}" ajax="true" update="@all"/> 
                            <p:commandButton id="decline2" value="Decline" action="#{notificationBean.rifiuta(j.sender)}" ajax="true" update="@all"/>
                            <br /><br />
                        </h:panelGroup>
                    </ui:repeat>    
                </h:panelGrid>
                <ui:repeat var="j" value="#{notificationView.friendNotificationList}" >
                    <h:panelGroup rendered="#{j.unread}" >
                        <h:outputText value="accepted Friendship: " rendered="#{j.azione==10}"/>
                        <h:outputText value="declined Friendship: " rendered="#{j.azione==1}"/>
                        <h:outputText value="#{j.sender.name}" />
                    <br /><br />
                    </h:panelGroup>
                </ui:repeat>
             </p:panel>   
        </h:form>
    </h:body>
</html>

